package com.xiaoyang.userservice.controller;

import com.xiaoyang.userservice.domain.Order;
import com.xiaoyang.userservice.feign.UserOrderFeign;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * @auther XiaoYang
 * @DATE 2023/5/4-17:40
 */
@Slf4j
@RestController
public class UserController {

    @Autowired
    private UserOrderFeign userOrderFeign;

    /**
     * 总结
     * 浏览器(前端) ->  user-service(/userDoOrder) -> RPC(feign) -> order-service(/doOrder)
     * @return OrderService.doOrder()
     */
    @GetMapping("/userDoOrder")
    public String userDoOrder(){
        log.info("有用户进入点餐~");
        //这里需要发起一个远程调用
        String s = userOrderFeign.doOrder();
        return s;
    }

    @GetMapping("/testParam")
    public String testParam(){
        String cxk = userOrderFeign.testUrl("cxk", 18);
        log.info(cxk);

        String xiaoYang = userOrderFeign.oneParam("小羊");
        log.info(xiaoYang);

        String xiaoyang = userOrderFeign.twoParam("小羊", 18);
        log.info(xiaoyang);

        Order order = Order.builder()
                .name("牛排")
                .price(188D)
                .time(new Date())
                .id(1)
                .build();
        String oneObj = userOrderFeign.oneObj(order);
        log.info(oneObj);

        String oneObjOneParam = userOrderFeign.oneObjOneParam(order, "只因");
        log.info(oneObjOneParam);

        return "ok";

    }

    /**
     * Fri May 05 09:38:33 CST 2023
     * Fri May 05 23:38:33 CST 2023 +-14h
     *
     * 不建议单独传递时间参数
     * 转成字符串 字符串不会改变
     * jdk8的时间类型 LocalDate 只有年月日 这个不会变
     *              LocalDateTime 有年月日时分秒 这个会丢失秒
     * 改源码 更不建议
     * @return ok
     */
    @GetMapping("/time")
    public String time(){
        Date date = new Date();
        log.info("{}",date);
        String time = userOrderFeign.testTime(date);
        log.info(time);
        return "ok";
    }

}
